<?php
App::uses('ProductAppController', 'Product.Controller');
/**
 * Products Controller
 *
 */
class ProductsController extends ProductAppController {

/**
 * Scaffold
 *
 * @var mixed
 */
	public $scaffold;

	public function admin_index()
	{
		$this->Product->recursive = 0;
		$s_selected = null;
		$cond = array();
		if($this->request->is("post")) {
			$s_selected = $this->request->data['frm']['status'];
			$this->passedArgs["status"] = $this->request->data['frm']['status'];
			$s = $this->request->data['frm']['s'];
			$this->passedArgs["name"] = $this->request->data['frm']['s'];
			$cateproducts_id = $this->request->data['frm']['cateproducts_id'];
			$this->passedArgs["cateproducts_id"] = $this->request->data['frm']['cateproducts_id'];
		}
		if(isset($this->passedArgs["status"])) {
			$cond = array_merge($cond,array('Product.status'=>$this->passedArgs["status"]));
			$s_selected = $this->passedArgs["status"];
		}
		if(isset($this->passedArgs["name"])) {
			$cond = array_merge($cond,array('Product.name LIKE'=>'%'.$this->passedArgs["name"].'%'));
			$s = $this->passedArgs["name"];
		}
		if(isset($this->passedArgs["cateproducts_id"])) {
			$cond = array_merge($cond,array('Product.cateproducts_id'=>$this->passedArgs["cateproducts_id"]));
		}

		if($s_selected == 0){
			unset($cond['Product.status']);
		}
		if(empty($cateproducts_id )){
			unset($cond['Product.cateproducts_id']);
		}
		$this->Paginator->settings = array("conditions"=>$cond,"order"=>"Product.id desc");

		$this->set('products', $this->Paginator->paginate());
		$this->set(compact("s_selected"));
		$cateproducts = $this->Product->Cateproducts->find('list');
		$this->set(compact('cateproducts'));
	}
	public function admin_add()
	{
		# code...
	}
	public function admin_edit()
	{
		# code...
	}
	public function admin_delete()
	{
		# code...
	}
	public function index($value='')
	{
		# code...
	}
}
